<template>
	<view>
		<!-- 裁剪 -->
		<qf-image-cropper :width="w" :height="h" @crop="handleCrop" :src="src"></qf-image-cropper>
	</view>
</template>

<script>
	import qfImageCropper from '../components/qf-image-cropper/qf-image-cropper'
	import {
		ossUpload,
		ossDel
	} from '@/common/oss.js'
	export default {
		components: {
			'qf-image-cropper': qfImageCropper
		},
		data() {
			return {
				w: 0,
				h: 0,
				type: 1,
				src: ''
			}
		},
		onLoad(e) {
			this.w = e.w
			this.h = e.h
			this.type = e.type
			this.src = ''
			if (e.type == 1) {
				this.$refs.qfImageCropper.chooseImage({
					sourceType: ['album']
				});
			} else if (e.type == 2) {
				this.src = this.$store.state.shareQuery
			} else if (e.type == 3) {
				this.src = this.$store.state.publishUrl
			}

		},
		methods: {
			handleCrop(e) {
				//console.log('daixa',uni.getFileInfoSync({ filePath: e.tempFilePath }))
				uni.getFileInfo({
					filePath: e.tempFilePath,
					success: (info) => {
						console.log('info', info, info.size)
						const MAXSIZE = 10
						const maxSize = MAXSIZE * 1024 * 1024; // 最大允许图片大小：5MB
						if (info.size > maxSize) {
							let title = '图片大小不能超过' + MAXSIZE + 'MB'
							uni.showToast({duration:3000,
								title,
								icon: 'none'
							})
						} else {
							// this.uploadImage(tempFilePaths[0]);
						
							ossUpload(e.tempFilePath).then(res => {
								
	
								
								if (this.type == 1) {
									this.$store.commit('setCropperUrl', res.url)
								} else if (this.type == 2) {
									this.$store.commit('setShareCropperUrl', res.url)
								} else if (this.type == 3) {
									this.$store.commit('setPublishUrl', res.url)
								}else  if (this.type == 4) {
									this.$store.commit('setCjj', res.url)
							
								}else  if (this.type == 5) {
									this.$store.commit('setVideoMask', res.url)
							
								}
							
								uni.navigateBack()
							}).catch(err => {
								uni.showToast({duration:3000,
									title: '上传失败！',
									icon: 'none'
								})
							})

						}
					}
				})

			},
		}
	}
</script>

<style>
</style>